<% layout('/layouts/default.html', {title: '检修车回送单管理', libs: ['dataGrid']}){ %>
<div class="main-content">
	<div class="box box-main">
		<div class="box-header">
			<div class="box-title">
				<i class="fa icon-notebook"></i> ${text('检修车回送单管理')}
			</div>
			<div class="box-tools pull-right">
				<a href="#" class="btn btn-default" id="btnSearch" title="${text('查询')}"><i class="fa fa-filter"></i> ${text('查询')}</a>
				<a href="#" class="btn btn-default" id="btnSetting" title="${text('设置')}"><i class="fa fa-navicon"></i></a>
			</div>
		</div>
		<div class="box-body">
			<#form:form id="searchForm" model="${tblXdJxchsd}" action="${ctx}/tbl/replyform/tblXdJxchsd/listData" method="post" class="form-inline" data-page-no="${parameter.pageNo}" data-page-size="${999}" data-order-by="${parameter.orderBy}">
				<div class="form-group">
					<label class="control-label">${text('车站')}：</label>
					<div class="control-inline width-120">
						<#form:select path="dqczbh" items="${lineList}" itemLabel="stationName" itemValue="stationCode" class="form-control" onchange="stationChange()" blankOption="true"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('列检线路')}：</label>
					<div class="control-inline width-120">
						<#form:select path="dqxlbh"  items="${lineListByStation}" itemLabel="" itemValue="lineCode" class="form-control"/>
					</div>
				</div>
				<div class="form-group">
					<button type="submit" class="btn btn-primary btn-sm">${text('查询')}</button>
					<button type="reset" class="btn btn-default btn-sm">${text('重置')}</button>
					<button onclick="updBtn()" class="btn btn-primary btn-sm">${text('修改')}</button>
					<button onclick="delBtn()" class="btn btn-primary btn-sm">${text('删除')}</button>
					<button onclick="sendBtn()" class="btn btn-primary btn-sm">${text('通知偏重')}</button>
					<button onclick="backBtn()" class="btn btn-primary btn-sm">${text('撤销偏重')}</button>
					<button onclick="sendByNBtn()" class="btn btn-primary btn-sm">${text('通知偏重（北部列检专用）')}</button>
				</div>
			</#form:form>
			<table id="dataGrid"></table>
<!--			<div id="dataGridPage"></div>-->
			<div id="comnfirmBox" data-url="${ctx}/tbl/replyform/tblXdJxchsd/form" style="display: none">
				<div id="comnfirmBox1" data-url="${ctx}/tbl/replyform/tblXdJxchsd/form1" style="display: none">
		</div>
	</div>
</div>
<% } %>
<script>
function delBtn(){
	var ids = $("#dataGrid").jqGrid("getGridParam", "selarrrow");
	if(ids.length==0){
		js.showMessage('请选择要删除的记录。', '', 'warning', 4000);
		return;
	}else{
		var msg = "确定进行【删除】操作？";
		js.confirm(msg,function(data){
			var jhhString = "";//拼接字符串
			for(var i=0;i<ids.length;i++){
				jhhString += "^"+ids[i];
			}
			console.log(jhhString);
			if(""!=jhhString) {
				jhhString=jhhString.substring(1);
			}
			console.log(jhhString);
		    $.post("${ctx}/tbl/replyform/tblXdJxchsd/delete",{'jhhString':jhhString},function(e){
		    	$('#dataGrid').trigger("reloadGrid");
		        },"json");
		});
	}
}
function sendBtn(){
	var ids = $("#dataGrid").jqGrid("getGridParam", "selarrrow");
	if(ids.length==0){
		js.showMessage('请选择要发送的车号。', '', 'warning', 4000);
		return;
	}else{
		var msg = "确定进行【发送】操作？";
		js.confirm(msg,function(data){
			var jhhString = "";//拼接字符串
			for(var i=0;i<ids.length;i++){
				jhhString += "^"+ids[i];
			}
			console.log(jhhString);
			if(""!=jhhString) {
				jhhString=jhhString.substring(1);
			}
			console.log(jhhString);
			$.post("${ctx}/tbl/replyform/tblXdJxchsd/send",{'jhhString':jhhString},function(e){
				$('#dataGrid').trigger("reloadGrid");
			},"json");
		});
	}
}

function sendByNBtn(){
	var ids = $("#dataGrid").jqGrid("getGridParam", "selarrrow");
	console.log(ids) ;
	var jhhString = ""; // 拼接字符串
	for(var i = 0; i < ids.length; i++){
		jhhString += "," + ids[i];
	}
	if(jhhString !== "") {
		jhhString = jhhString.substring(1);
	}
	console.log(jhhString);
	if(ids.length>0){
		$('#comnfirmBox').show();
		js.layer.open({
			type: 2,
			title:['偏重确认','background-color:#e2e1e1;'],
			align:'center',
			area: ['1200px', '600px'], //宽高
			content: $('#comnfirmBox1').attr('data-url')+"?recId="+ids[0]+"&ids="+jhhString,
			shade: 0.5 ,
			resize:false,//弹窗不可拖拽
			end : function(){
				$('#comnfirmBox').hide();
				$('#dataGrid').trigger("reloadGrid");
			}
		});
	}else{
		js.showMessage('请选择一条记录。', '', 'warning', 4000);
		return;
	}
}


function backBtn(){
	var ids = $("#dataGrid").jqGrid("getGridParam", "selarrrow");
	if(ids.length==0){
		js.showMessage('请选择要撤销的记录。', '', 'warning', 4000);
		return;
	}else{
		var msg = "确定进行【撤消】操作？";
		js.confirm(msg,function(data){
			var jhhString = "";//拼接字符串
			for(var i=0;i<ids.length;i++){
				jhhString += "^"+ids[i];
			}
			console.log(jhhString);
			if(""!=jhhString) {
				jhhString=jhhString.substring(1);
			}
			console.log(jhhString);
			$.post("${ctx}/tbl/replyform/tblXdJxchsd/back",{'jhhString':jhhString},function(e){
				$('#dataGrid').trigger("reloadGrid");
			},"json");
		});
	}
}

//确认
function updBtn(){
	var ids = $("#dataGrid").jqGrid("getGridParam", "selarrrow");
	console.log(ids) ;
	var jhhString = ""; // 拼接字符串
	for(var i = 0; i < ids.length; i++){
		jhhString += "," + ids[i];
	}
	if(jhhString !== "") {
		jhhString = jhhString.substring(1);
	}
	console.log(jhhString);
	if(ids.length>0){
		$('#comnfirmBox').show();
		js.layer.open({
			type: 2,
			title:['列检确认','background-color:#e2e1e1;'],
			align:'center',
			area: ['1200px', '600px'], //宽高
			content: $('#comnfirmBox').attr('data-url')+"?recId="+ids[0]+"&ids="+jhhString,
			shade: 0.5 ,
			resize:false,//弹窗不可拖拽
			end : function(){
				$('#comnfirmBox').hide();
				$('#dataGrid').trigger("reloadGrid");
			}
		});
	}else{
		js.showMessage('请选择一条记录。', '', 'warning', 4000);
		return;
	}
}


// 初始化DataGrid对象
$('#dataGrid').dataGrid({
	searchForm: $("#searchForm"),
	multiselect:true,
	rownumWidth:40,
	shrinkToFit:false,
	columnModel: [
		{header:'${text("运用号")}', name:'wagonno', index:'a.wagonno', width:150, align:"center", frozen:true},
		{header:'${text("入修地点")}', name:'repairLineName', index:'a.repair_line_name', width:150, align:"center"},
		{header:'${text("货物")}', name:'goodsName', index:'a.good_name', width:150, align:"center"},
		{header:'${text("扣车类别")}', name:'faultItemName', index:'a.fault_name', width:150, align:"center"},
		{header:'${text("扣车原因")}', name:'faultName', index:'a.fault_name', width:150, align:"center"},
		{header:'${text("入修类别")}', name:'repairMethod', index:'a.repair_method', width:150, align:"center"},
		{header:'${text("入修方式")}', name:'repairMethodDetail', index:'a.repair_method_detail', width:150, align:"center"},
		{header:'${text("上峰")}', name:'isNopeak', index:'a.is_nopeak', width:150, align:"center", formatter: function(val, obj, row, act){
				return js.getDictLabel(${@DictUtils.getDictListJson('sys_yes_no')}, val, '${text("未知")}', true);
			}},
		{header:'${text("限速")}', name:'speedLimit', index:'a.speed_limit', width:150, align:"center"},
		{header:'${text("是否偏重")}', name:'focusArea', index:'a.focusArea', width:150, align:"center",formatter: function(val, obj, row, act){
				return js.getDictLabel(${@DictUtils.getDictListJson('sys_yes_no')}, val, '${text("未知")}', true);
			}},
		{header:'${text("通知时间")}', name:'stationTime', index:'a.station_time', width:180, align:"center"},
		{header:'${text("办理时间")}', name:'workStartTime', index:'a.work_start_time', width:180, align:"center"},
		{header:'${text("列检员")}', name:'ljUsername', index:'a.lj_username', width:150, align:"center"},
		{header:'${text("检车人")}', name:'jcrName', index:'a.jcr_name', width:150, align:"center"},
		{header:'${text("列检调度")}', name:'ljddUsername', index:'a.ljdd_username', width:150, align:"center"},
		{header:'${text("车站调度")}', name:'czddUsername', index:'a.czdd_username', width:150, align:"center"},
		{header:'${text("更新人")}', name:'userName', index:'a.user_name', width:150, align:"center"},
		{header:'${text("更新时间")}', name:'updTime', index:'a.upd_time', width:180, align:"center"},
		{header:'${text("备注")}', name:'remark', index:'a.remark', width:150, align:"center"}

	],
	// 加载成功后执行事件
	ajaxSuccess: function(data){
		const array = JSON.parse(sessionStorage.getItem("检修车回送单管理"))
		if(array && array.length > 0){
			for (const item of array) {
				$('#dataGrid').dataGrid('setSelectRow', item, false);
			}
		}
	},
	onSelectRow: function(id, isSelect, event){
		const array = $('#dataGrid').dataGrid('getSelectRows')
		sessionStorage.setItem("检修车回送单管理", JSON.stringify(array))
	},
}).dataGrid('setLabel', 'rn', '序号');

$('button[type="reset"]').on('click', function() {
	//移除暂存
	sessionStorage.removeItem("检修车回送单管理")
	$('#dataGrid').dataGrid('resetSelection');
})

function stationChange(){
	var params={"stationCode":$("#dqczbh").val()};//车站
	$("#dqxlbh").empty();
	$("#dqxlbh").val("");
	var url = "${ctx}/tbl/replyform/tblXdJxchsd/getLineList1";
	$("input[name='deviceNo']:checkbox").each(function(){
		if((this).checked == true)
		{
			url = "${ctx}/tbl/replyform/tblXdJxchsd/getLineList1";
		}
	})
	$.post(url,params,function(data){
		//debugger;
		if(data.tblXdLjzyjlList.length!=1){
			$("#dqxlbh").append('<option value=""> </option>');
		}
		for(var key in data.tblXdLjzyjlList){
			var row=data.tblXdLjzyjlList[key];
			console.log(111,key);
			$("#dqxlbh").append('<option value="'+row.lineCode+'">'+row.line+'</option>');
		}
	},"json");
}
</script>
<style>
	.laydate-btns-clear{
		display: none !important;
	}
</style>